﻿<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/xadmin.css">
    <script type="text/javascript" src="/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/js/xadmin.js"></script>
</head>
<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">演示</a>
            <a>
                <cite>导航元素</cite>
            </a>
        </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
        </a>
    </div>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-tab">
                        <ul class="layui-tab-title">
                            <li class="layui-this">手动抓取</li>
                            <li>定时抓取</li>
                        </ul>
                        <div class="layui-tab-content">
                            <div class="layui-tab-item layui-show">
                                <form class="layui-form" id="form">
                                    <div style="width:100%;padding-top:20px">
                                        <div class="layui-form-item" style="width: 60%;margin:auto">
                                            <div class="layui-input-inline" style="width:60%">
                                                <input placeholder="请输入需要抓取的文章链接" required lay-verify="required" value="{{$.title}}" type="text" id="url" name="url" autocomplete="off" class="layui-input">
                                            </div>
                                            <label class="layui-form-label" style="padding:unset;width:auto">
                                                <span id="layui-btn-manual" class="layui-btn" style="padding: 0px 15px;">抓取</span>
                                            </label>
                                        </div>
                                    </div>
                                </form>
                                    <div style="width:100%;padding-top:20px">
                                        <div id="layui-form-item-res" class="layui-form-item" style="width: 60%;margin:auto;text-align:center">
                                            
                                        </div>
                                    </div>
                            </div>
                            <div class="layui-tab-item">
                                <div class="layui-fluid">
                                    <div class="layui-row layui-col-space15">
                                        <div class="layui-col-md12">
                                            <div class="layui-card">
                                                <div class="layui-card-header">
                                                    <button class="layui-btn" onclick="xadmin.open('添加定时任务','{{urlfor "admin.ArticleResourcesController.GetCron"}}','600','400')">
                                                        <i class="layui-icon"></i>添加
                                                    </button>

                                                </div>
                                                <div class="layui-card-body ">
                                                    <table class="layui-table layui-form">
                                                        <thead>
                                                            <tr>
                                                                <th width="70">ID</th>
                                                                <th>标题</th>
                                                                <th>命令</th>
                                                                <th>链接</th>
                                                                <th>创建时间</th>
                                                                <th>更新时间</th>
                                                                <th width="250">操作</th>
</thead>
                                                        <tbody class="x-cate">
                                                            {{range $key ,$value := $.Data}}
                                                            <tr>
                                                                <td>{{$value.Id}}</td>
                                                                <td>
                                                                    {{$value.Title}}
                                                                </td>
                                                                <td>{{$value.Cron}}</td>
                                                                <td>
                                                                    {{$value.Url}}
                                                                </td>
                                                                <td>
                                                                    {{$value.Created}}
                                                                </td>
                                                                <td>
                                                                    {{$value.Updated}}
                                                                </td>
                                                                <td class="td-manage">
                                                                    <button class="layui-btn layui-btn layui-btn-xs" onclick="member_stop(this,'{{$value.Id}}')">
                                                                        {{if eq $value.Status 1}}
                                                                        停止
                                                                        {{else}}
                                                                        开始
                                                                        {{end}}
                                                                    </button>
                                                                    <button class="layui-btn-danger layui-btn layui-btn-xs" onclick="member_del(this,'{{$value.Id}}')" href="javascript:;"><i class="layui-icon">&#xe640;</i>删除</button>
                                                                </td>
                                                            </tr>
                                                            {{end}}
                                                        </tbody>
                                                    </table>
                                                </div>                                        
                                            </div>
                                        </div>
                                    </div>
                                </div>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
<script>
layui.use(['form', 'layer'], function() {
    $ = layui.jquery;


    $("#layui-btn-manual").click(function(){
        $.ajax({
        url:'/admin/article/get',
        type:'post',
        data: $("#form").serialize(),
        success:function (data) {
            console.log(data);
            if (data.code == 200){

                $("#layui-form-item-res").html('抓取结果：<span style="color:red">抓取成功，用时：' + data.elapsed + '，查看<a style="color: #002af9;" href="/detail/' + data.id + '.html" target="_blank"> ' + data.title + ' </a></span>')
               
            }else{
                $("#layui-form-item-res").html('抓取结果：<span style="color:red">抓取失败，Error：' + data.err + '</span>')
            }

        }
    });
    });
 })

        function member_stop(obj, id) {
              layer.confirm('确认要删除吗(将同步删除下级分类)？',
                  function(index){
                      $.ajax({
                          url:'/admin/cron/'+id,
                          type:'put',
                          success:function (data) {
                              //发异步删除数据
                              //$(obj).parents("tr").remove();
                              layer.msg('已删除!', {
                                  icon: 1,
                                  time: 1000
                              });
                              window.location.reload();
                    
                          }
                      });
                  });
          }
    function member_del(obj, id) {
              layer.confirm('确认要删除吗(将同步删除下级分类)？',
                  function(index) {
                      $.ajax({
                          url:'/admin/cron/'+id,
                          type:'delete',
                          //data:'id='+id,
                          success:function (data) {
                              //发异步删除数据
                              $(obj).parents("tr").remove();
                              layer.msg('已删除!', {
                                  icon: 1,
                                  time: 1000
                              });
                              window.location.reload();

                          }
                      });
                  });
          }
</script>